package business.manage.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import common.database.interfaces.BaseDAO;

import business.manage.user.argument.UserArgument;
import business.manage.user.dto.User;
@Service
public class UserService {
	@Autowired
	private BaseDAO baseDAO;
	
	private static String SELECT_SQL = "select Id,login_name loginName, password, person_name personName, phone_num phoneNum , is_admin isAdmin from sys_user t";
	
	private static String INSERT_SQL = "insert into sys_user(Id,login_name,password,person_name,phone_num,is_admin)values(:id,:loginName,:password,:personName,:phoneNum,:isAdmin)";
	
	public User findUser(UserArgument ua)throws Exception{
		String findUserSql = SELECT_SQL+" where t.login_name=? and PASSWORD=?";
		
		Object object_user = baseDAO.getJavaBean(findUserSql, User.class, ua.getLoginName(),ua.getPassword());
		if(object_user!=null){
			return (User)object_user;
		}
		return null;
	}
	
	public int addUser(User user)throws Exception{
		int result = baseDAO.update(INSERT_SQL, user);
		return result;
	}
}
